<template>

  <div>
    <div class="common-form">其它</div>
    <el-form-item label="优惠类型">
      <el-radio-group v-model="form.activity_type">
        <el-radio :label="1">按件数打折</el-radio>
        <el-radio :label="2">首件优惠，按x件起购</el-radio>
        <el-radio :label="3">满x件赠y件</el-radio>
      </el-radio-group>
    </el-form-item>
    
    <div v-if="form.activity_type ==1">

      <div class="d-s-c pt16 max-w460 active-all-set"  v-for="(item, index) in rebate_json" :key="index" >
        <el-form-item label="件数"  :rules="[{ required: true, message: '请填写件数' }]"><el-input type="number"  min="0" placeholder="件数" v-model="item.num" style="width: 100px;"></el-input></el-form-item>
        <el-form-item label="优惠折扣" :rules="[{ required: true, message: '请填写优惠折扣' }]"><el-input type="number"  min="0" placeholder="优惠折扣" v-model="item.rebate" style="width: 100px;"></el-input></el-form-item>
        <div class="ml10" v-if="rebate_json.length == index+1"><el-button @click="addItem">添加</el-button></div>
        <div class="ml10" v-else><el-button @click="removeItem">减去</el-button></div>
      </div>

    </div>

    <div v-if="form.activity_type ==2">
      <el-form-item label="首件价格" prop="first_price" :rules="[{ required: true, message: '请填写价格' }]"><el-input type="number" v-model="form.first_price" class="max-w460"></el-input></el-form-item>
      <el-form-item label="起购数量" prop="start_buy_num" :rules="[{ required: true, message: '请填写起购数量' }]"><el-input type="number" v-model="form.start_buy_num" class="max-w460"></el-input></el-form-item>
    </div>
    <div v-if="form.activity_type ==3">
      <el-form-item label="满购数量" prop="buy_num" :rules="[{ required: true, message: '请填写满购数量' }]"><el-input type="number" v-model="form.buy_num" class="max-w460"></el-input></el-form-item>
      <el-form-item label="赠送数量" prop="gift_num" :rules="[{ required: true, message: '请填写赠送数量' }]"><el-input type="number" v-model="form.gift_num" class="max-w460"></el-input></el-form-item>
      <el-form-item label="优惠金额" prop="gift_num" ><el-input type="number" v-model="form.discount_moeny" class="max-w460"></el-input></el-form-item>
      <el-form-item label="赠送限制">
      <el-radio-group v-model="form.limit_user">
        <el-radio :label="0">无限制</el-radio>
        <el-radio :label="1">一个用户ID只赠送一次</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="活动说明" prop="explain" ><el-input type="text" v-model="form.explain" class="max-w460"></el-input></el-form-item>
    </div>
    <el-form-item label="限购数量" prop="limit_num" :rules="[{ required: true, message: '请填写限购数量' }]"><el-input type="number" v-model="form.limit_num" class="max-w460"></el-input></el-form-item>
    <el-form-item label="活动标签" prop="tag" :rules="[{ required: true, message: '请填写活动标签' }]"><el-input type="text" v-model="form.tag" class="max-w460"></el-input></el-form-item>
  </div>

  
</template>

<script>
export default {
  inject: ['form'],
  created() {
    this.form.rebate_json 
    if(this.form.rebate_json != ''){
      this.rebate_json = this.form.rebate_json;
    }
    
  },
  data(){
    return{
      rebate_json:[
          {
            'num':0,
            'rebate':0
          }
        
        ]
    }
  },

methods: {
  addItem() {
    this.rebate_json.push({'num':'','rebate':''});
    this.form.rebate_json = this.rebate_json
  },

  removeItem() {
    if (this.rebate_json.length > 0) {
      this.rebate_json.pop();
      this.form.rebate_json = this.rebate_json;
    }
  }

}
};
</script>

<style></style>
